<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="68px">
      <el-form-item label="学生id" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学生id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试日期" prop="interviewDate">
        <el-date-picker
          v-model="queryParams.interviewDate"
          clearable
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择面试日期"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司地址" prop="companyAddress">
        <el-input
          v-model="queryParams.companyAddress"
          placeholder="请输入公司地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司联系人" prop="companyContact">
        <el-input
          v-model="queryParams.companyContact"
          placeholder="请输入公司联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="contact">
        <el-input
          v-model="queryParams.contact"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试结果" prop="interviewResults">
        <el-input
          v-model="queryParams.interviewResults"
          placeholder="请输入面试结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试总结" prop="interviewSummary">
        <el-input
          v-model="queryParams.interviewSummary"
          placeholder="请输入面试总结"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试题图片" prop="interviewQuestions">
        <el-input
          v-model="queryParams.interviewQuestions"
          placeholder="请输入面试题图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试简历" prop="interviewResume">
        <el-input
          v-model="queryParams.interviewResume"
          placeholder="请输入面试简历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['interview:interviewlist:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['interview:interviewlist:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['interview:interviewlist:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['interview:interviewlist:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="interviewlistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="面试信息id" align="center" prop="interviewId" />
      <el-table-column label="学生id" align="center" prop="studentId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="面试日期" align="center" prop="interviewDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.interviewDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="公司地址" align="center" prop="companyAddress" />
      <el-table-column label="公司联系人" align="center" prop="companyContact" />
      <el-table-column label="联系方式" align="center" prop="contact" />
      <el-table-column label="面试结果" align="center" prop="interviewResults" />
      <el-table-column label="面试内容" align="center" prop="interviewContent" />
      <el-table-column label="面试总结" align="center" prop="interviewSummary" />
      <el-table-column label="面试题图片" align="center" prop="interviewQuestions" width="300" />
      <el-table-column label="面试简历" align="center" prop="interviewResume" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['interview:interviewlist:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            v-hasPermi="['interview:interviewlist:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改面试信息列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="面试日期" prop="interviewDate">
          <el-date-picker
            v-model="form.interviewDate"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择面试日期"
          />
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="公司地址" prop="companyAddress">
          <el-input v-model="form.companyAddress" placeholder="请输入公司地址" />
        </el-form-item>
        <el-form-item label="公司联系人" prop="companyContact">
          <el-input v-model="form.companyContact" placeholder="请输入公司联系人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="面试结果" prop="interviewResults">
          <el-input v-model="form.interviewResults" placeholder="请输入面试结果" />
        </el-form-item>
        <el-form-item label="面试内容">
          <editor v-model="form.interviewContent" :min-height="192" />
        </el-form-item>
        <el-form-item label="面试总结" prop="interviewSummary">
          <el-input v-model="form.interviewSummary" placeholder="请输入面试总结" />
        </el-form-item>
        <el-form-item label="面试题图片" prop="interviewQuestions">
          <el-input v-model="form.interviewQuestions" placeholder="请输入面试题图片" />
        </el-form-item>
        <el-form-item label="面试简历" prop="interviewResume">
          <el-input v-model="form.interviewResume" placeholder="请输入面试简历" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInterviewlist, getInterviewlist, delInterviewlist, addInterviewlist, updateInterviewlist } from '@/api/interview/interviewlist'

export default {
  name: 'Interviewlist',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 面试信息列表表格数据
      interviewlistList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentId: null,
        name: null,
        interviewDate: null,
        companyName: null,
        companyAddress: null,
        companyContact: null,
        contact: null,
        interviewResults: null,
        interviewContent: null,
        interviewSummary: null,
        interviewQuestions: null,
        interviewResume: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [
          { required: true, message: '学生id不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        interviewDate: [
          { required: true, message: '面试日期不能为空', trigger: 'blur' }
        ],
        companyName: [
          { required: true, message: '公司名称不能为空', trigger: 'blur' }
        ],
        companyAddress: [
          { required: true, message: '公司地址不能为空', trigger: 'blur' }
        ],
        companyContact: [
          { required: true, message: '公司联系人不能为空', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '联系方式不能为空', trigger: 'blur' }
        ],
        interviewResults: [
          { required: true, message: '面试结果不能为空', trigger: 'blur' }
        ],
        interviewContent: [
          { required: true, message: '面试内容不能为空', trigger: 'blur' }
        ],
        interviewSummary: [
          { required: true, message: '面试总结不能为空', trigger: 'blur' }
        ],
        interviewResume: [
          { required: true, message: '面试简历不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询面试信息列表列表 */
    getList() {
      this.loading = true
      listInterviewlist(this.queryParams).then(response => {
        this.interviewlistList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        interviewId: null,
        studentId: null,
        name: null,
        interviewDate: null,
        companyName: null,
        companyAddress: null,
        companyContact: null,
        contact: null,
        interviewResults: null,
        interviewContent: null,
        interviewSummary: null,
        interviewQuestions: null,
        interviewResume: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.interviewId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加面试信息列表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const interviewId = row.interviewId || this.ids
      getInterviewlist(interviewId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改面试信息列表'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.interviewId != null) {
            updateInterviewlist(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addInterviewlist(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const interviewIds = row.interviewId || this.ids
      this.$modal.confirm('是否确认删除面试信息列表编号为"' + interviewIds + '"的数据项？').then(function() {
        return delInterviewlist(interviewIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('interview/interviewlist/export', {
        ...this.queryParams
      }, `interviewlist_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style>
  .aaa{
    height: 100px;
    overflow-y: auto;
  }
</style>
